home *** CD-ROM | disk | FTP | other *** search
/ Hardcore Visual Basic 5.0 (2nd Edition) / Hardcore Visual Basic 5.0 - Second Edition (1997)(Microsoft Press).iso / Code / Goodies / ICONWO~1 / VIEWICON.FRM < prev    next >
Text File  |  1997-06-09  |  41KB  |  1,177 lines

  1. VERSION 5.00
  2. Begin VB.Form Viewer 
  3.    Caption         =   "IconWorks Viewer"
  4.    ClientHeight    =   4248
  5.    ClientLeft      =   1452
  6.    ClientTop       =   1872
  7.    ClientWidth     =   5904
  8.    ClipControls    =   0   'False
  9.    BeginProperty Font 
  10.       Name            =   "Courier"
  11.       Size            =   9.6
  12.       Charset         =   0
  13.       Weight          =   400
  14.       Underline       =   0   'False
  15.       Italic          =   0   'False
  16.       Strikethrough   =   0   'False
  17.    EndProperty
  18.    FontTransparent =   0   'False
  19.    ForeColor       =   &H00000000&
  20.    Icon            =   "VIEWICON.frx":0000
  21.    LinkMode        =   1  'Source
  22.    LinkTopic       =   "Form1"
  23.    PaletteMode     =   1  'UseZOrder
  24.    ScaleHeight     =   354
  25.    ScaleMode       =   3  'Pixel
  26.    ScaleWidth      =   492
  27.    Tag             =   "IconWrks Viewer"
  28.    Begin VB.PictureBox Pic_SelectedIconLabel 
  29.       BackColor       =   &H00FFFFFF&
  30.       BorderStyle     =   0  'None
  31.       BeginProperty Font 
  32.          Name            =   "MS Sans Serif"
  33.          Size            =   13.8
  34.          Charset         =   0
  35.          Weight          =   400
  36.          Underline       =   0   'False
  37.          Italic          =   0   'False
  38.          Strikethrough   =   0   'False
  39.       EndProperty
  40.       FontTransparent =   0   'False
  41.       ForeColor       =   &H000000FF&
  42.       Height          =   525
  43.       Left            =   15
  44.       ScaleHeight     =   44
  45.       ScaleMode       =   3  'Pixel
  46.       ScaleWidth      =   295
  47.       TabIndex        =   16
  48.       Top             =   0
  49.       Width           =   3540
  50.       Begin VB.PictureBox Pic_IconsBitmap 
  51.          AutoRedraw      =   -1  'True
  52.          BackColor       =   &H0000FF00&
  53.          BorderStyle     =   0  'None
  54.          BeginProperty Font 
  55.             Name            =   "System"
  56.             Size            =   9.6
  57.             Charset         =   0
  58.             Weight          =   700
  59.             Underline       =   0   'False
  60.             Italic          =   0   'False
  61.             Strikethrough   =   0   'False
  62.          EndProperty
  63.          Height          =   510
  64.          Left            =   0
  65.          ScaleHeight     =   43
  66.          ScaleMode       =   3  'Pixel
  67.          ScaleWidth      =   43
  68.          TabIndex        =   0
  69.          Top             =   0
  70.          Visible         =   0   'False
  71.          Width           =   510
  72.       End
  73.       Begin VB.PictureBox Pic_SelectedIcon 
  74.          BackColor       =   &H000000FF&
  75.          BorderStyle     =   0  'None
  76.          BeginProperty Font 
  77.             Name            =   "System"
  78.             Size            =   9.6
  79.             Charset         =   0
  80.             Weight          =   700
  81.             Underline       =   0   'False
  82.             Italic          =   0   'False
  83.             Strikethrough   =   0   'False
  84.          EndProperty
  85.          Height          =   480
  86.          Left            =   3045
  87.          ScaleHeight     =   40
  88.          ScaleMode       =   3  'Pixel
  89.          ScaleWidth      =   40
  90.          TabIndex        =   9
  91.          Top             =   30
  92.          Width           =   480
  93.       End
  94.    End
  95.    Begin VB.PictureBox Pic_VerticalLine 
  96.       BackColor       =   &H00000000&
  97.       BorderStyle     =   0  'None
  98.       Enabled         =   0   'False
  99.       BeginProperty Font 
  100.          Name            =   "System"
  101.          Size            =   9.6
  102.          Charset         =   0
  103.          Weight          =   700
  104.          Underline       =   0   'False
  105.          Italic          =   0   'False
  106.          Strikethrough   =   0   'False
  107.       EndProperty
  108.       Height          =   4245
  109.       Left            =   3555
  110.       ScaleHeight     =   4248
  111.       ScaleWidth      =   12
  112.       TabIndex        =   10
  113.       Top             =   0
  114.       Width           =   15
  115.    End
  116.    Begin VB.PictureBox Pic_AllIcons 
  117.       BackColor       =   &H00FFFFFF&
  118.       BorderStyle     =   0  'None
  119.       BeginProperty Font 
  120.          Name            =   "System"
  121.          Size            =   9.6
  122.          Charset         =   0
  123.          Weight          =   700
  124.          Underline       =   0   'False
  125.          Italic          =   0   'False
  126.          Strikethrough   =   0   'False
  127.       EndProperty
  128.       Height          =   4245
  129.       Left            =   3570
  130.       MousePointer    =   10  'Up Arrow
  131.       ScaleHeight     =   354
  132.       ScaleMode       =   3  'Pixel
  133.       ScaleWidth      =   173
  134.       TabIndex        =   11
  135.       TabStop         =   0   'False
  136.       Top             =   0
  137.       Visible         =   0   'False
  138.       Width           =   2070
  139.    End
  140.    Begin VB.VScrollBar Scrl_AllIcons 
  141.       Height          =   4275
  142.       Left            =   5640
  143.       TabIndex        =   12
  144.       Top             =   -15
  145.       Visible         =   0   'False
  146.       Width           =   270
  147.    End
  148.    Begin VB.TextBox Txt_FileName 
  149.       BeginProperty Font 
  150.          Name            =   "MS Sans Serif"
  151.          Size            =   7.8
  152.          Charset         =   0
  153.          Weight          =   700
  154.          Underline       =   0   'False
  155.          Italic          =   0   'False
  156.          Strikethrough   =   0   'False
  157.       EndProperty
  158.       Height          =   330
  159.       Left            =   795
  160.       TabIndex        =   1
  161.       Top             =   525
  162.       Width           =   2775
  163.    End
  164.    Begin VB.PictureBox Pic_IconCount 
  165.       BackColor       =   &H00FF0000&
  166.       BorderStyle     =   0  'None
  167.       BeginProperty Font 
  168.          Name            =   "MS Sans Serif"
  169.          Size            =   7.8
  170.          Charset         =   0
  171.          Weight          =   400
  172.          Underline       =   0   'False
  173.          Italic          =   0   'False
  174.          Strikethrough   =   0   'False
  175.       EndProperty
  176.       FontTransparent =   0   'False
  177.       ForeColor       =   &H00FFFFFF&
  178.       Height          =   210
  179.       Left            =   1365
  180.       ScaleHeight     =   216
  181.       ScaleWidth      =   420
  182.       TabIndex        =   13
  183.       Top             =   1335
  184.       Visible         =   0   'False
  185.       Width           =   420
  186.    End
  187.    Begin VB.DirListBox Dir_DirectoryList 
  188.       BeginProperty Font 
  189.          Name            =   "MS Sans Serif"
  190.          Size            =   7.8
  191.          Charset         =   0
  192.          Weight          =   700
  193.          Underline       =   0   'False
  194.          Italic          =   0   'False
  195.          Strikethrough   =   0   'False
  196.       EndProperty
  197.       Height          =   2055
  198.       Left            =   -15
  199.       TabIndex        =   3
  200.       Top             =   1560
  201.       Width           =   1800
  202.    End
  203.    Begin VB.FileListBox File_FileList 
  204.       BeginProperty Font 
  205.          Name            =   "MS Sans Serif"
  206.          Size            =   7.8
  207.          Charset         =   0
  208.          Weight          =   700
  209.          Underline       =   0   'False
  210.          Italic          =   0   'False
  211.          Strikethrough   =   0   'False
  212.       EndProperty
  213.       Height          =   1992
  214.       Left            =   1770
  215.       Pattern         =   "*.ico"
  216.       TabIndex        =   5
  217.       Top             =   1560
  218.       Width           =   1800
  219.    End
  220.    Begin VB.DriveListBox Drv_DriveList 
  221.       BeginProperty Font 
  222.          Name            =   "MS Sans Serif"
  223.          Size            =   7.8
  224.          Charset         =   0
  225.          Weight          =   700
  226.          Underline       =   0   'False
  227.          Italic          =   0   'False
  228.          Strikethrough   =   0   'False
  229.       EndProperty
  230.       Height          =   1530
  231.       Left            =   -15
  232.       TabIndex        =   7
  233.       Top             =   3945
  234.       Width           =   3585
  235.    End
  236.    Begin VB.Line line_HorizontalLine 
  237.       X1              =   0
  238.       X2              =   235
  239.       Y1              =   35
  240.       Y2              =   35
  241.    End
  242.    Begin VB.Label Lbl_File 
  243.       Caption         =   "Fi&le:"
  244.       BeginProperty Font 
  245.          Name            =   "MS Sans Serif"
  246.          Size            =   7.8
  247.          Charset         =   0
  248.          Weight          =   700
  249.          Underline       =   0   'False
  250.          Italic          =   0   'False
  251.          Strikethrough   =   0   'False
  252.       EndProperty
  253.       Height          =   210
  254.       Left            =   0
  255.       TabIndex        =   8
  256.       Top             =   585
  257.       Width           =   795
  258.    End
  259.    Begin VB.Label Lbl_Directory 
  260.       Caption         =   "Directory:"
  261.       BeginProperty Font 
  262.          Name            =   "MS Sans Serif"
  263.          Size            =   7.8
  264.          Charset         =   0
  265.          Weight          =   700
  266.          Underline       =   0   'False
  267.          Italic          =   0   'False
  268.          Strikethrough   =   0   'False
  269.       EndProperty
  270.       Height          =   210
  271.       Left            =   0
  272.       TabIndex        =   14
  273.       Top             =   870
  274.       Width           =   1380
  275.    End
  276.    Begin VB.Label Lbl_CurrentDirectory 
  277.       Alignment       =   2  'Center
  278.       BorderStyle     =   1  'Fixed Single
  279.       BeginProperty Font 
  280.          Name            =   "MS Sans Serif"
  281.          Size            =   7.8
  282.          Charset         =   0
  283.          Weight          =   700
  284.          Underline       =   0   'False
  285.          Italic          =   0   'False
  286.          Strikethrough   =   0   'False
  287.       EndProperty
  288.       Height          =   240
  289.       Left            =   -15
  290.       TabIndex        =   15
  291.       Top             =   1080
  292.       Width           =   3585
  293.    End
  294.    Begin VB.Label Lbl_Directories 
  295.       Caption         =   "&Directories:"
  296.       BeginProperty Font 
  297.          Name            =   "MS Sans Serif"
  298.          Size            =   7.8
  299.          Charset         =   0
  300.          Weight          =   700
  301.          Underline       =   0   'False
  302.          Italic          =   0   'False
  303.          Strikethrough   =   0   'False
  304.       EndProperty
  305.       Height          =   210
  306.       Left            =   0
  307.       TabIndex        =   2
  308.       Top             =   1335
  309.       Width           =   1365
  310.    End
  311.    Begin VB.Label Lbl_Icons 
  312.       Alignment       =   2  'Center
  313.       Caption         =   "&Icons"
  314.       BeginProperty Font 
  315.          Name            =   "MS Sans Serif"
  316.          Size            =   7.8
  317.          Charset         =   0
  318.          Weight          =   700
  319.          Underline       =   0   'False
  320.          Italic          =   0   'False
  321.          Strikethrough   =   0   'False
  322.       EndProperty
  323.       Height          =   210
  324.       Left            =   1785
  325.       TabIndex        =   4
  326.       Top             =   1335
  327.       Width           =   1755
  328.    End
  329.    Begin VB.Label Lbl_Drives 
  330.       Caption         =   "Dri&ves:"
  331.       BeginProperty Font 
  332.          Name            =   "MS Sans Serif"
  333.          Size            =   7.8
  334.          Charset         =   0
  335.          Weight          =   700
  336.          Underline       =   0   'False
  337.          Italic          =   0   'False
  338.          Strikethrough   =   0   'False
  339.       EndProperty
  340.       Height          =   210
  341.       Left            =   0
  342.       TabIndex        =   6
  343.       Top             =   3735
  344.       Width           =   1365
  345.    End
  346.    Begin VB.Menu Menu_File 
  347.       Caption         =   "&File"
  348.       Begin VB.Menu Menu_FileSelection 
  349.          Caption         =   "&Open"
  350.          Index           =   1
  351.       End
  352.       Begin VB.Menu Menu_FileSelection 
  353.          Caption         =   "-"
  354.          Index           =   2
  355.       End
  356.       Begin VB.Menu Menu_FileSelection 
  357.          Caption         =   "E&xit"
  358.          Index           =   5
  359.       End
  360.    End
  361.    Begin VB.Menu Menu_Edit 
  362.       Caption         =   "&Edit"
  363.       Begin VB.Menu Menu_EditCopy 
  364.          Caption         =   "&Copy"
  365.       End
  366.    End
  367.    Begin VB.Menu Menu_Options 
  368.       Caption         =   "&Options"
  369.       Begin VB.Menu Menu_OptionsSelection 
  370.          Caption         =   "&Editor..."
  371.          Index           =   0
  372.          Shortcut        =   {F7}
  373.       End
  374.       Begin VB.Menu Menu_OptionsSelection 
  375.          Caption         =   "&Show all Icons"
  376.          Index           =   1
  377.          Shortcut        =   ^V
  378.       End
  379.       Begin VB.Menu Menu_OptionsSelection 
  380.          Caption         =   "-"
  381.          Index           =   2
  382.       End
  383.       Begin VB.Menu Menu_OptionsSelection 
  384.          Caption         =   "Show all icons on &DIR change"
  385.          Index           =   3
  386.       End
  387.    End
  388.    Begin VB.Menu Menu_Help 
  389.       Caption         =   "&Help"
  390.       Begin VB.Menu Menu_HelpSelection 
  391.          Caption         =   "&Index"
  392.          Index           =   1
  393.          Shortcut        =   {F1}
  394.       End
  395.       Begin VB.Menu Menu_HelpSelection 
  396.          Caption         =   "&Keyboard"
  397.          Index           =   2
  398.       End
  399.       Begin VB.Menu Menu_HelpSelection 
  400.          Caption         =   "&Commands"
  401.          Index           =   3
  402.       End
  403.       Begin VB.Menu Menu_HelpSelection 
  404.          Caption         =   "&Using Help"
  405.          Index           =   4
  406.       End
  407.       Begin VB.Menu Menu_HelpSelection 
  408.          Caption         =   "-"
  409.          Index           =   5
  410.       End
  411.       Begin VB.Menu Menu_HelpSelection 
  412.          Caption         =   "&About..."
  413.          Index           =   6
  414.       End
  415.    End
  416. End
  417. Attribute VB_Name = "Viewer"
  418. Attribute VB_GlobalNameSpace = False
  419. Attribute VB_Creatable = False
  420. Attribute VB_PredeclaredId = True
  421. Attribute VB_Exposed = False
  422.  
  423.  
  424.  
  425. DefInt A-Z
  426.  
  427. Dim Badicon
  428.  
  429. Private Sub Adjust_All_Controls()
  430.   
  431.     ' Save the visibility state of the Icon viewing window, since
  432.     ' we resize it whether it is visible or not.
  433.     '
  434.     AllIconsVisible = Pic_AllIcons.Visible
  435.  
  436.     ' Hide all controls that can be resized, while the actual resizing is
  437.     ' being done.  This prevents uneccessary screen updates.
  438.     '
  439.     Pic_AllIcons.Visible = False
  440.     Scrl_AllIcons.Visible = False
  441.     File_FileList.Visible = False
  442.     Dir_DirectoryList.Visible = False
  443.  
  444.     ' Calculate number of icon rows and columns for the new Window size,
  445.     ' and the maximum number of icons that can be displayed at once
  446.     ' within the new window size.
  447.     '
  448.     IconRows = ScaleHeight \ ICON_CELL
  449.     IconColumns = (ScaleWidth - Pic_AllIcons.Left) \ ICON_CELL
  450.     MaxIcons = IconColumns * IconRows
  451.   
  452.     ' Set new width for the icon viewing area
  453.     '
  454.     NewAllIconsWidth = ScaleWidth - Pic_AllIcons.Left + 1
  455.  
  456.     ' Check if there are more icons than can be displayed at once in the viewing window
  457.     '
  458.     If File_FileList.ListCount > MaxIcons Then
  459.         '
  460.         ' All the icons cannot be displayed at once, so the viewing area must be
  461.         ' reset, the Viewing area Scrollbar must be reset, and the number of icon
  462.         ' columns must be reset since the scrollbar now takes up part of the viewing area.
  463.         '
  464.         Scrl_AllIcons.Left = ScaleWidth - Scrl_AllIcons.Width + 1
  465.         NewAllIconsWidth = Scrl_AllIcons.Left - Pic_AllIcons.Left
  466.         IconColumns = NewAllIconsWidth \ ICON_CELL
  467.         MaxIcons = IconColumns * IconRows
  468.     End If
  469.       
  470.     ' Resize and Repostion affected controls
  471.     '
  472.     Pic_AllIcons.Move Pic_AllIcons.Left, Pic_AllIcons.Top, NewAllIconsWidth, ScaleHeight
  473.     Scrl_AllIcons.Height = ScaleHeight + 2
  474.     Pic_VerticalLine.Height = ScaleHeight
  475.     Drv_DriveList.Top = ScaleHeight - Drv_DriveList.Height + 1
  476.     Lbl_Drives.Top = Drv_DriveList.Top - Lbl_Drives.Height
  477.     File_FileList.Height = Lbl_Drives.Top - Dir_DirectoryList.Top - 1
  478.     Dir_DirectoryList.Height = File_FileList.Height
  479.  
  480.     ' Redisplay controls hidden before resizing and reposition was done
  481.     '
  482.     Pic_AllIcons.Visible = AllIconsVisible
  483.     File_FileList.Visible = True
  484.     Dir_DirectoryList.Visible = True
  485.  
  486. End Sub
  487.  
  488. Private Sub Dir_DirectoryList_Change()
  489.   
  490.     ' A new directory has been selected, so Set current directory
  491.     ' to the newly selected directory
  492.     '
  493.     ChDir Dir_DirectoryList.Path
  494.     
  495.     ' Display the newly selected directory
  496.     '
  497.     Lbl_CurrentDirectory.Caption = Dir_DirectoryList.Path
  498.  
  499.     ' Inform the File ListBox of the PathChange.
  500.     '
  501.     File_FileList.Path = Dir_DirectoryList.Path
  502.  
  503.     ' Display new filespec in FileName TextBox
  504.     '
  505.     UpDate_FileSpec Viewer
  506.  
  507. End Sub
  508.  
  509. Private Sub Dir_DirectoryList_Click()
  510.     
  511.     ' The actual directory has not changed since the Directory ListBox was
  512.     ' only single clicked , so all we need to do is display the new file
  513.     ' spec for the selected directory in the FileName TextBox.
  514.     '
  515.     UpDate_FileSpec Viewer
  516.     VLastChanged = DIR_CHANGED
  517.  
  518. End Sub
  519.  
  520. Private Sub Dir_DirectoryList_KeyPress(KeyAscii As Integer)
  521.  
  522.     ' Pressing Enter when the Directory ListBox has the Focus should
  523.     ' react just as if the Directory ListBox was double clicked, so all we
  524.     ' need to do is set the Path property of the Directory control to the
  525.     ' selected directory.
  526.     '
  527.     If KeyAscii = 13 Then Dir_DirectoryList.Path = Dir_DirectoryList.List(Dir_DirectoryList.ListIndex)
  528.  
  529. End Sub
  530.  
  531. Private Sub Drv_DriveList_Change()
  532.  
  533.     ' Selecting a drive from a Drive control does not generate an error
  534.     ' if the selected drive is not ready, so we verify that the drive is
  535.     ' in fact ready before we accept the drive.
  536.     '
  537.     Validate_And_Change_Drives Viewer
  538.  
  539. End Sub
  540.  
  541. Private Sub File_FileList_Click()
  542.  
  543.     If File_FileList.ListIndex >= 0 Then
  544.         ' When a file is selected from the File Listbox with single click
  545.         ' from the mouse, this routine displays the selected icon just above
  546.         ' the file listbox if it is a valid Icon file.
  547.         '
  548.         Txt_FileName.Text = File_FileList.FileName
  549.         Badicon = Not Valid_Icon((File_FileList.FileName), True)
  550.         If Not Badicon Then
  551.             '
  552.             ' File is valid Icon file
  553.             '
  554.             Menu_EditCopy.Enabled = True
  555.             VLastChanged = FILE_CHANGED
  556.         End If
  557.     End If
  558.  
  559. End Sub
  560.  
  561. Private Sub File_FileList_DblClick()
  562.   
  563.     ' Double Clicking a file within the File ListBox signals that an
  564.     ' existing file has been selected, so attempt to open the file.
  565.     '
  566.     If Not Badicon Then
  567.         VLastChanged = FILE_CHANGED
  568.         Open_Selected_Icon
  569.     End If
  570.  
  571. End Sub
  572.  
  573. Private Sub File_FileList_KeyPress(KeyAscii As Integer)
  574.     
  575.     ' Pressing Enter when the File ListBox has the Focus should react
  576.     ' just as if the File ListBox was Double Clicked, so all we need
  577.     ' to do is attempt to open the selected file.
  578.     '
  579.     VLastChanged = FILE_CHANGED
  580.     If KeyAscii = 13 Then Open_Selected_Icon
  581.  
  582. End Sub
  583.  
  584. Private Sub File_FileList_PathChange()
  585.     
  586.     ShowingAllIcons = False
  587.     
  588.     If (File_FileList.ListCount > 0) And Menu_OptionsSelection(MID_SHOW_ON_DIR_CHANGE).Checked Then
  589.         '
  590.         ' There are icons in the new directory and the user has selected
  591.         ' to automatically display all icons when the directory is changed,
  592.         ' so we simulate selecting the menu item which displays all the icons.
  593.         '
  594.         Menu_OptionsSelection_Click MID_SHOW_ALL_ICONS
  595.     Else
  596.         ' There are no icons in the current directory, or the user does
  597.         ' not want to automatically display all icons when the directory
  598.         ' changes, so we need to get rid of all displayed icons.
  599.         '
  600.         Scrl_AllIcons.Visible = False
  601.         Pic_AllIcons.Visible = False
  602.         Pic_SelectedIcon.Picture = LoadPicture()
  603.     End If
  604.  
  605.     ' The menu item to show all icons, is enabled if the current directory
  606.     ' contains icons, and disabled if it does not.
  607.     '
  608.     Menu_OptionsSelection(MID_SHOW_ALL_ICONS).Enabled = File_FileList.ListCount > 0
  609.  
  610.     ' Display the number of icons in the current directory
  611.     '
  612.     Lbl_Icons.Caption = Format$(File_FileList.ListCount) + " &Icons"
  613.  
  614. End Sub
  615.  
  616. Private Sub Form_Load()
  617.  
  618.     Pic_IconsBitmap.Move 0, 0, 34, 34
  619.     Pic_SelectedIcon.Move Pic_SelectedIcon.Left, Pic_SelectedIcon.Top, 32, 32
  620.     Pic_SelectedIcon.BackColor = WHITE
  621.     Pic_IconsBitmap.BackColor = WHITE
  622.  
  623.     ' Inform rest of Iconworks that the Viewer is loaded.  Viewer.Visible could
  624.     ' be tested but accessing the visible property would cause the Viewer to be
  625.     ' loaded if not already loaded.
  626.     '
  627.     ViewerLoaded = True
  628.  
  629.     Menu_OptionsSelection(MID_SHOW_ON_DIR_CHANGE).Checked = -GetPrivateProfileInt(APP_NAME, KEY_SHOW_ICONS, 0, INI_FILENAME)
  630.  
  631.     ' Position Viewer at 0,0, and set Width and Height to 2/3's that of the Screen.
  632.     '
  633.     Move 0, 0, Screen.Width * 0.66, Screen.Height * 0.66
  634.  
  635.     ' Calculate the Minimum width and Height for the Viewer.  This is done, so
  636.     ' the smallest window allowed will still allow easy access to all controls.
  637.     '
  638.     MinViewerWidth = (Pic_VerticalLine.Left + Scrl_AllIcons.Width + ICON_CELL + 2) * 15 + (Width - ScaleWidth * 15)
  639.     MinViewerHeight = ICON_CELL * 6 * 15 + (Height - ScaleHeight * 15)
  640.  
  641.     ' Enable the "Show all icons' menu option only if the current directory
  642.     ' contains icons
  643.     '
  644.     Menu_OptionsSelection(MID_SHOW_ALL_ICONS).Enabled = File_FileList.ListCount > 0
  645.  
  646.     ' Display the number of icons in the current directory, display the
  647.     ' current directory, and set the current file name to the default
  648.     ' file spec of "*.ICO", which was set at design time into the File
  649.     ' ListBox.
  650.     '
  651.     Lbl_Icons.Caption = Format$(File_FileList.ListCount) + " &Icons"
  652.     Lbl_CurrentDirectory.Caption = Dir_DirectoryList.Path
  653.     Txt_FileName.Text = File_FileList.Pattern
  654.  
  655.     VLastChanged = DIR_CHANGED
  656.     
  657.     ' The Alt+F4 accelerator for Exit, cannot be assigned using the Menu
  658.     ' design Window, so we need to put the accelerator into the caption.
  659.     ' Alt+F4 is actually the System menus Close option.
  660.     '
  661.     Menu_FileSelection(MID_EXIT).Caption = "E&xit" + A_TAB + "Alt+F4"
  662.                                         
  663.     Show
  664.     Refresh
  665.     If Menu_OptionsSelection(MID_SHOW_ON_DIR_CHANGE).Checked And (File_FileList.ListCount <> 0) Then Menu_OptionsSelection_Click MID_SHOW_ALL_ICONS
  666.  
  667. End Sub
  668.  
  669. Private Sub Form_Resize()
  670.   
  671.     ' The Form has been resized, so we need to resize and possible reposition
  672.     ' some of the controls on the form, however, we do not want to do anything
  673.     ' if the form is minimized.
  674.     '
  675.     If WindowState <> MINIMIZED Then
  676.         '
  677.         ' Check if new size is less than the minimum Viewer size.
  678.         '
  679.         If (Width < MinViewerWidth) Or (Height < MinViewerHeight) Then
  680.             '
  681.             ' The form is smaller than the minimum size, either in width or
  682.             ' height, so reset the width and/or height to the minimum values.
  683.             '
  684.             If Width < MinViewerWidth Then NewWidth = MinViewerWidth Else NewWidth = Width
  685.             If Height < MinViewerHeight Then NewHeight = MinViewerHeight Else NewHeight = Height
  686.             Move Left, Top, NewWidth, NewHeight
  687.         Else
  688.             ' The form is greater than the minimum width and height values
  689.             ' so adjust any controls that need resizing or repositioning.
  690.             '
  691.             Adjust_All_Controls
  692.  
  693.             Scrl_AllIcons.Value = 0
  694.  
  695.             If (File_FileList.ListCount > MaxIcons) And ShowingAllIcons Then
  696.                 '
  697.                 ' There are more icons that can be displayed at once within
  698.                 ' the current new size of the Form, so we need to calculate
  699.                 ' new Max and LargeChange values for the scrollbar.
  700.                 '
  701.                 Diff = File_FileList.ListCount - MaxIcons
  702.                 Scrl_AllIcons.Max = Diff \ IconColumns
  703.                 If (Diff Mod IconColumns) Then Scrl_AllIcons.Max = Scrl_AllIcons.Max + 1
  704.                 Scrl_AllIcons.LargeChange = IconRows
  705.                 Scrl_AllIcons.Visible = True ' And (File_FileList.ListCount > MaxIcons)
  706.             End If
  707.         End If
  708.     End If
  709. End Sub
  710.  
  711. Private Sub Form_Unload(Cancel As Integer)
  712.  
  713.     ' Let the rest of IconWorks know that the Viewer is no longer loaded.
  714.     '
  715.     ViewerLoaded = False
  716.     ShowingAllIcons = False
  717.     R = WinHelp(hWnd, dummy$, HELP_QUIT, 0)
  718.  
  719.     R = WritePrivateProfileString(APP_NAME, KEY_SHOW_ICONS, Format$(Abs(Menu_OptionsSelection(MID_SHOW_ON_DIR_CHANGE).Checked)), INI_FILENAME)
  720.  
  721.     ' If the Viewer was started up first then we treat it as the main Form.
  722.     ' So, if the Editor is loaded, we should as the user if the Editor should
  723.     ' also be terminated.
  724.     '
  725.     If (MainForm = ICONWORKS_VIEWER) And (EditorLoaded) Then
  726.         '
  727.         ' Viewer was started first and the Editor is loaded so ask the user
  728.         ' if the Editor should also be terminated.
  729.         '
  730.         Text = "Terminate Editor Also?"
  731.         If MsgBox(Text, 36, "IconWorks") = MBYES Then Unload Editor
  732.         MainForm = ICONWORKS_EDITOR
  733.     End If
  734.  
  735. End Sub
  736.  
  737. ' When a request is made to display all the icons in the current directory
  738. ' this routine is called to perform the task.
  739. '
  740. Private Sub Load_All_Icons()
  741.     
  742.     If CurDir$ <> File_FileList.Path Then ChDir File_FileList.Path
  743.  
  744.     ' Refresh the File listbox to pick up any files that might have been
  745.     ' added to the current directory since this directory was selected.
  746.     '
  747.     File_FileList.Refresh
  748.  
  749.     ' Determine if the scrollbar is needed.  If there are more icons in the
  750.     ' current directory than can be displayed at once, the scrollbar must
  751.     ' be active to allow viewing of all the icons.
  752.     '
  753.     Scrl_AllIcons.Visible = File_FileList.ListCount > MaxIcons
  754.     Scrl_AllIcons.Value = 0
  755.  
  756.     ' Display the Icon Viewing window
  757.     '
  758.     Pic_AllIcons.Visible = True
  759.      
  760.     ' When all the icons are displayed, a single bitmap is created and maintained
  761.     ' in memory.  This bitmap contains the images of all the icons in the current
  762.     ' directory.  This bitmap is used to update the Viewing Window when the window
  763.     ' is scrolled or when the Form is resized.  The bitmap is made of the image
  764.     ' of each icon concatenated into one long bitmap.  This makes for a very fast
  765.     ' screen update when the icons need to be redisplayed.  The icons do not have
  766.     ' to be reloaded each time, but simply copied from this bitmap to the viewing
  767.     ' window.
  768.     '
  769.     Pic_IconsBitmap.Width = File_FileList.ListCount * ICON_CELL
  770.     Pic_IconsBitmap.Cls
  771.  
  772.     ' To build the memory Icon Bitmap above, each icon must be loaded at least
  773.     ' once so as to obtain its image and add it to the memory bitmap.  The
  774.     ' Pic_SelectedIcon picture contol is used for this purpose, but to prevent
  775.     ' uneccessary flashing of this picture control as each icon is loaded,
  776.     ' it is hidden while this is going on.  And since it is hidden while this
  777.     ' is occuring, AutoRedraw must be set to TRUE to allow copying of the image
  778.     ' while it is hidden.  The image is copied using the Windows API routine
  779.     ' BitBlt().
  780.     '
  781.     Pic_SelectedIcon.Visible = False
  782.     Pic_SelectedIcon.AutoRedraw = True
  783.  
  784.     ' So something is visibly happening while the icons are being loaded and the
  785.     ' bitmap is being created, the File Listbox label's color is changed, and
  786.     ' the Lbl_IconCount is made visible.  These labels count and display the number
  787.     ' of icons loaded as they are being loaded.
  788.     '
  789.     Lbl_Icons.Caption = "Icons Loaded"
  790.     Lbl_Icons.ForeColor = WHITE
  791.     Lbl_Icons.BackColor = RED
  792.     Lbl_Icons.Refresh
  793.     Pic_IconCount.Visible = True
  794.     
  795.     ' Attempt to load all files listed in the File ListBox.  If valid Icon files
  796.     ' add image to memory bitmap.
  797.     '
  798.     Screen.MousePointer = HOURGLASS
  799.     For X = 0 To File_FileList.ListCount - 1
  800.         '
  801.         ' Display current count of Icons loaded
  802.         '
  803.         Pic_IconCount.CurrentX = 0
  804.         Pic_IconCount.Print X + 1; "  ";
  805.         If Valid_Icon((File_FileList.List(X)), False) Then
  806.             '
  807.             ' The file was a valid Icon file, so add its image to the memory Bitamp
  808.             '
  809.             R = BitBlt(Pic_IconsBitmap.hDC, 2 + X * ICON_CELL, 0, 32, 32, Pic_SelectedIcon.hDC, 0, 0, SRCCOPY)
  810.         Else
  811.             ' The file was not a valid Icon file, so display a BLACK square where the icons
  812.             ' image would have been placed within the Memory bitmap.
  813.             '
  814.             R = BitBlt(Pic_IconsBitmap.hDC, 2 + X * ICON_CELL, 0, 32, 32, 0, 0, 0, BLACKNESS)
  815.         End If
  816.     Next X
  817.     Screen.MousePointer = DEFAULT
  818.  
  819.     ' Re-Display the SelectedIcon picture and disable its AutoRedraw since
  820.     ' it is no longer needed.
  821.     '
  822.     Pic_SelectedIcon.Visible = True
  823.     Pic_SelectedIcon.AutoRedraw = False
  824.  
  825.     ' Reset the File list Labels to normal, and display the total number of Icons loaded.
  826.     '
  827.     Lbl_Icons.ForeColor = WINDOW_TEXT
  828.     Lbl_Icons.BackColor = WINDOW_BACKGROUND
  829.     Lbl_Icons.Caption = Format$(File_FileList.ListCount) + " &Icons"
  830.  
  831.     ' Hide the IconCount label since it is not needed except while loading icons.
  832.     '
  833.     Pic_IconCount.Visible = False
  834.  
  835. End Sub
  836.  
  837. Private Sub Menu_EditCopy_Click()
  838.   
  839.     ' Can't place an actual Icon into the System clipboard, so place
  840.     ' a bitmap of its image, in response to a copy command.
  841.     '
  842.     Clipboard.Clear
  843.     Clipboard.SetData Pic_SelectedIcon.Image
  844.   
  845. End Sub
  846.  
  847. Private Sub Menu_File_Click()
  848.  
  849.     ' Before displaying the file menu, enable or disable the File.Open
  850.     ' command, based on whether or not an Icon is currently selected.
  851.     '
  852.     Menu_FileSelection(MID_OPEN).Enabled = File_FileList.ListIndex >= 0
  853.  
  854. End Sub
  855.  
  856. Private Sub Menu_FileSelection_Click(Index As Integer)
  857.  
  858.     ' One of the 2 File menu items were selected, so determine which one
  859.     ' and perform the corresponding task.
  860.     '
  861.     Select Case Index
  862.         
  863.         Case MID_OPEN
  864.             Open_Selected_Icon
  865.             
  866.         Case MID_EXIT
  867.             Unload Viewer
  868.  
  869.     End Select
  870.  
  871. End Sub
  872.  
  873. Private Sub Menu_HelpSelection_Click(Index As Integer)
  874.  
  875.     If Index < MID_ABOUT Then
  876.         '
  877.         ' Determine what help topic to display.  The *Index* and *Using Help*
  878.         ' items are the same for both the Viewer and the Editor, but the
  879.         ' items: Keyboard and Commands are different and have
  880.         ' different Help topic ID's, so we add 3 to the Menu item which
  881.         ' will then make the Index correspond to the correct Help topic.
  882.         '
  883.         If (Index >= MID_KEYBOARD) And (Index <= MID_COMMANDS) Then Index = Index + 3
  884.         Get_Help Index
  885.     Else
  886.         ' Display the IconWorks About box
  887.         '
  888.         AboutBox.Show MODAL
  889.     End If
  890.  
  891. End Sub
  892.  
  893. Private Sub Menu_OptionsSelection_Click(Index As Integer)
  894.     
  895.     ' One of the 3 Options menu items were selected, so determine which one
  896.     ' and perform the corresponding task.
  897.     '
  898.     Select Case Index
  899.         
  900.         Case MID_EDITOR
  901.             ' Invoke the Editor, but do not open the selected Icon
  902.             '
  903.             Editor.Show MODELESS
  904.  
  905.         Case MID_SHOW_ALL_ICONS
  906.             ' Check for too man Icons to display.  maximum of 963.
  907.             '
  908.             If File_FileList.ListCount > 900 Then
  909.                 MsgBox "Can display upto a maximum of 900 icons", 16, "Too many Icons"
  910.             Else
  911.                 '
  912.                 ' Let the rest of the Viewer know that all the Icons are currently
  913.                 ' begin displayed.
  914.                 '
  915.                 Temp = ShowingAllIcons
  916.                 ShowingAllIcons = True
  917.     
  918.                 ' Before showing all the icons, the values for the scrollbar must
  919.                 ' be re-calculated based on the number of icons in the current
  920.                 ' directory.  Since this is done when the form is resized, we can
  921.                 ' accomplish this by calling the Form_Resize event to do this for us.
  922.                 '
  923.                 If Not Temp Then Form_Resize
  924.                  
  925.                 ' We disable the Edit.Copy menu Item, since after all icons are
  926.                 ' displayed, no one icon will be selected yet.
  927.                 '
  928.                 Menu_EditCopy.Enabled = False
  929.     
  930.                 ' Load all the icons and then display them
  931.                 '
  932.                 Load_All_Icons
  933.                 Update_Displayed_Icons
  934.             End If
  935.  
  936.         Case MID_SHOW_ON_DIR_CHANGE
  937.             '
  938.             ' Toggle the Checked property of the *Show all icons* options.
  939.             '
  940.             Menu_OptionsSelection(MID_SHOW_ON_DIR_CHANGE).Checked = Not Menu_OptionsSelection(MID_SHOW_ON_DIR_CHANGE).Checked
  941.             If Menu_OptionsSelection(MID_SHOW_ON_DIR_CHANGE).Checked And Menu_OptionsSelection(MID_SHOW_ALL_ICONS).Enabled Then Menu_OptionsSelection_Click MID_SHOW_ALL_ICONS
  942.     
  943.     End Select
  944.  
  945. End Sub
  946.  
  947. Private Sub Open_Selected_Icon()
  948. Dim OldPattern As String
  949.  
  950.     If VLastChanged = DIR_CHANGED Then
  951.         '
  952.         ' The directory was the last control accessed, so we need only
  953.         ' set its Path to is currently selected item, which will generate
  954.         ' a Change event for the Directory control, which will take care
  955.         ' of updating the other related controls
  956.         '
  957.         Dir_DirectoryList.Path = Dir_DirectoryList.List(Dir_DirectoryList.ListIndex)
  958.     Else
  959.         ' The FileName TextBox or the File ListBox was last accessed.
  960.         '
  961.         ValidName = True
  962.  
  963.         ' Validate the filename only if the FileName TextBox was the last
  964.         ' control accessed.  We do not need to Validate the Filename if the
  965.         ' File ListBox was last accessed since if the FileName is listed,
  966.         ' then the File exists.
  967.         '
  968.         If VLastChanged = FILENAME_CHANGED Then ValidName = Validate_FileSpec(Viewer, True)
  969.       
  970.         ' The FileName entered into the FileName TextBox many have contained
  971.         ' a new drive and path, so in case it did, we need to inform the
  972.         ' Drive and Directory controls of this change.
  973.         '
  974.         ChDir File_FileList.Path
  975.         Drv_DriveList.Drive = Left$(File_FileList.Path, 2)
  976.         Dir_DirectoryList.Path = File_FileList.Path
  977.  
  978.         If ValidName Then
  979.             If Valid_Icon((Txt_FileName.Text), True) Then
  980.                 '
  981.                 ' A file has been selected so invoke the Editor, and load the
  982.                 ' icon into the editor.
  983.                 '
  984.                 Editor.Show MODELESS
  985.                 Load_An_Icon
  986.             End If
  987.         End If
  988.     End If
  989.  
  990. End Sub
  991.  
  992. Private Sub Pic_AllIcons_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  993.  
  994.     ' Selections are made only with the Left mouse button.
  995.     '
  996.     If Button = LEFT_BUTTON Then
  997.         '
  998.         ' We need to determine if an icon was has actually been selected
  999.         ' by the MouseDown event, since an Icon does not exist at every
  1000.         ' location within the Viewing area (Pic_AllIcons).  So, we
  1001.         ' need to calculate the icon position selected based on the
  1002.         ' mouse coordinates and then check if an Icon exists at that location.
  1003.     
  1004.         ' Calculate the column of the selected Icon position.
  1005.         '
  1006.         XIcon = X \ ICON_CELL
  1007.         
  1008.         ' Determine if any icons exist in that column.
  1009.         '
  1010.         If XIcon < IconColumns Then
  1011.             '
  1012.             ' A valid Column has been selected, so we now need to calculate
  1013.             ' the selected Row position.  The Scrollbar's value must be
  1014.             ' considered when calculating the Row.
  1015.             '
  1016.             YIcon = Y \ ICON_CELL + Scrl_AllIcons.Value
  1017.  
  1018.             ' Using the Column and Row selected, calculate the actual
  1019.             ' Icon position selected.
  1020.             '
  1021.             SelectedIcon = (YIcon * IconColumns) + XIcon
  1022.  
  1023.             ' Determine if an Icon exists at the selected location
  1024.             '
  1025.             If SelectedIcon < File_FileList.ListCount Then
  1026.                 '
  1027.                 ' An icon has been selected, so select the Icon in the File ListBox
  1028.                 '
  1029.                 File_FileList.ListIndex = -1
  1030.                 File_FileList.ListIndex = SelectedIcon
  1031.  
  1032.                 ' If icon is a valid Win 3.0 icon, begin dragging.
  1033.                 '
  1034.                 If Not Badicon Then
  1035.                     Pic_AllIcons.DragIcon = Pic_SelectedIcon.DragIcon
  1036.                     Pic_AllIcons.Drag
  1037.                 End If
  1038.             End If
  1039.         End If
  1040.     End If
  1041. End Sub
  1042.  
  1043. Private Sub Pic_AllIcons_Paint()
  1044.  
  1045.     ' A portion of the viewing area needs to be updated, so if we
  1046.     ' are currently displaying any icons, Update the viewing area.
  1047.     '
  1048.     If ShowingAllIcons And (File_FileList.ListCount > 0) Then Update_Displayed_Icons
  1049.  
  1050. End Sub
  1051.  
  1052. Private Sub Pic_SelectedIcon_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  1053.   
  1054.     If (Button = LEFT_BUTTON) And (File_FileList.ListIndex >= 0) Then
  1055.         '
  1056.         ' Set the DragIcon to the Selected Icon so we see the actual icon
  1057.         ' when dragging, instead of an inverted Frame of the picture control,
  1058.         ' and begin dragging the icon.
  1059.         '
  1060.         'Pic_SelectedIcon.DragIcon = Pic_SelectedIcon.Picture
  1061.         Pic_SelectedIcon.Drag
  1062.     End If
  1063.  
  1064. End Sub
  1065.  
  1066. Private Sub Pic_SelectedIconLabel_Paint()
  1067.  
  1068.     Text = "Selected Icon:"
  1069.     Pic_SelectedIconLabel.CurrentX = (Pic_SelectedIconLabel.ScaleWidth - Pic_SelectedIconLabel.TextWidth(Text)) \ 2
  1070.     Pic_SelectedIconLabel.CurrentY = (Pic_SelectedIconLabel.ScaleHeight - Pic_SelectedIconLabel.TextHeight(Text)) \ 2
  1071.     Pic_SelectedIconLabel.Print Text
  1072.  
  1073. End Sub
  1074.  
  1075. Private Sub Scrl_AllIcons_Change()
  1076.  
  1077.     ' The Scrollbar was scrolled, so we need to scroll the displayed
  1078.     ' icons within the viewing window.  The Update_Displayed_Icons
  1079.     ' procedure displays the Icons based on the Value of the scrollbar
  1080.     ' if the scrollbar is currently visible.
  1081.     '
  1082.     Update_Displayed_Icons
  1083.  
  1084. End Sub
  1085.  
  1086. Private Sub Txt_FileName_Change()
  1087.   
  1088.     VLastChanged = FILENAME_CHANGED
  1089.  
  1090. End Sub
  1091.  
  1092. Private Sub Txt_FileName_KeyPress(KeyAscii As Integer)
  1093.   
  1094.     If KeyAscii = 13 Then
  1095.         '
  1096.         ' Enter was pressed, so cancel the KeyStroke to prevent a Beep,
  1097.         ' and attempt to open the selected file as an Icon.
  1098.         '
  1099.         KeyAscii = 0
  1100.         Open_Selected_Icon
  1101.     End If
  1102.  
  1103. End Sub
  1104.  
  1105. Private Sub Update_Displayed_Icons()
  1106.     
  1107.     ' When the form is resized, the scrollbar is scrolled, or anything causing the
  1108.     ' currently displayed icons to be updated, this routine is called to display
  1109.     ' or redisplay the icons in the viewing window.
  1110.     '
  1111.     ' Clear the viewing window to White.  The .Cls method could be used, but
  1112.     ' it causes excessive flashing, so the .Line method is used instead to
  1113.     ' draw a filled white box inside the viewing window, which accomplishes
  1114.     ' the same thing but a little more efficiently.
  1115.     '
  1116.     Pic_AllIcons.Line (0, (IconRows - 1) * ICON_CELL)-(Pic_AllIcons.Width, Pic_AllIcons.Height), WHITE, BF
  1117.     
  1118.     ' Calculate the number of icon rows that need to be displayed.  It could
  1119.     ' be all the rows or only a few if all the icons can fit in the current size
  1120.     ' of the viewing window.
  1121.     '
  1122.     NumIconRows = IconRows
  1123.     If MaxIcons > File_FileList.ListCount Then NumIconRows = File_FileList.ListCount \ IconColumns
  1124.  
  1125.     ' Determine what icon should be the first icon displayed (Upper left hand
  1126.     ' corner of viewing window) based on the current value of the Scrollbar.
  1127.     '
  1128.     FirstIcon = Scrl_AllIcons.Value * IconColumns
  1129.  
  1130.     ' An entire row of Icons is displayed at once which is copied from the memory
  1131.     ' bitmap of the icon images.  So we need to calculate the width in pixels
  1132.     ' of the current with of a row of Icons, since this can change whenever the
  1133.     ' form is resized.
  1134.     '
  1135.     PixelWidth = IconColumns * ICON_CELL
  1136.     xSrc = FirstIcon * ICON_CELL
  1137.     Y = 1
  1138.  
  1139.     ' Copy icons from the memory Bitmap one row at a time to the viewing window
  1140.     '
  1141.     For row = 0 To NumIconRows
  1142.         R = BitBlt(Pic_AllIcons.hDC, 0, Y, PixelWidth, ICON_CELL, Pic_IconsBitmap.hDC, xSrc, 0, SRCCOPY)
  1143.         xSrc = xSrc + PixelWidth
  1144.         Y = Y + ICON_CELL
  1145.     Next row
  1146.  
  1147. End Sub
  1148.  
  1149. Private Function Valid_Icon(FileName As String, Prompt)
  1150.     
  1151.     On Error Resume Next
  1152.  
  1153.     ' Set Err to no Error (FALSE) and attempt to load the selected file
  1154.     '
  1155.     Err = False
  1156.     Pic_SelectedIcon.DragIcon = LoadPicture(FileName)
  1157.     If Err And Prompt Then
  1158.         '
  1159.         ' The file is not a valid Icon file
  1160.         '
  1161.         Beep
  1162.         X = MsgBox(FileName + " is not a valid Win 3.0 .ICO file", 16, "Bad File")
  1163.         Pic_SelectedIcon.Picture = LoadPicture()
  1164.         Menu_EditCopy.Enabled = False
  1165.         Txt_FileName.Text = File_FileList.Pattern
  1166.         VLastChanged = DIR_CHANGED
  1167.     ElseIf Not Err Then
  1168.         Pic_SelectedIcon.Picture = Pic_SelectedIcon.DragIcon
  1169.     End If
  1170.  
  1171.     Valid_Icon = (Err = 0)
  1172.     
  1173.     On Error GoTo 0
  1174.  
  1175. End Function
  1176.  
  1177.